<?php
class SearchController extends AppController {
	var $name = 'Search';

	var $uses = array (
		'SysParams',
		'Job',
		'Company',
		'CompanyAccount',
		'JobArea',
		'JobCategory',
		'Member',
		'Order',
		'MailJob',
		'BookMark',
		'MemberResume',
	    'MemberEducation', 
		'MemberWork',
		'MemberExpWorktype'
	);

	function index() {
		$this->initPageLeft();
		$this->pageTitle='カモメ中国転職：求人検索';
		$areas=$this->SysParams->generateList("\"SysParams\".kbn = 'area_id' and \"SysParams\".deleted is null","order by id asc");
		$temas=$this->SysParams->generateList("\"SysParams\".kbn = 'tema_id' and \"SysParams\".deleted is null","order by id asc");
		$this->Session->del('job_search_conditions');
		$this->set('temas',$temas);
		$this->set('areas',$areas);
		$this->render();
	}
	
	//@author wangyuhua 2012/4/17 start
	/* function job_search(){
		$this->initPageLeft();
		$this->pageTitle='カモメ中国転職：求人検索';
		$condition="\"Job\".deleted is null and \"Job\".search_flg=0 and (\"Job\".\"public_start\"||' '||\"Job\".\"public_start_hour\"||':'||\"Job\".\"public_start_min\") <= to_char(now(),'YYYY-MM-DD HH24:MI') and (\"Job\".\"public_end\"||' '||\"Job\".\"public_end_hour\"||':'||\"Job\".\"public_end_min\")>=to_char(now(),'YYYY-MM-DD HH24:MI')" .
				" and \"Job\".job_status_id=1 and \"Job\".public_close_date is NULL";

		$data = $this->data;
		$f=$this->Session->read("form");
		
		if(!empty($this->data['Search'])){
			$condition.=' and '.$this->createCondition($this->Search,$this->data);
			$this->Session->del('form');
			$form = $data;
			$this->Session->write('form',$form);
			
			$this->Session->write('job_search_conditions',$condition);
		}
		else{
			if($this->Session->check('job_search_conditions')){
				$condition = $this->Session->read('job_search_conditions');
			}
		
			$form=$f;
		}
		
		$this->set('form',$form);
		$jobs=$this->Job->findAll($condition,null,'Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc',$this->show,$this->page);
		$count=$this->Job->findCount($condition);
		
		$condition1=$condition.' AND to_char("Job"."attention_start",\'YYYY-MM-DD\') <= to_char(now(),\'YYYY-MM-DD\') AND to_char("Job"."attention_end",\'YYYY-MM-DD\') >= to_char(now(),\'YYYY-MM-DD\') and "Job".attention_search_flg=1';
		$this->set('attention_jobs',$this->Job->findAll($condition1,null,'Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc'));
		$condition2=$condition.' AND to_char("Job"."pickup_start",\'YYYY-MM-DD\') <= to_char(now(),\'YYYY-MM-DD\') AND to_char("Job"."pickup_end",\'YYYY-MM-DD\') >= to_char(now(),\'YYYY-MM-DD\') and Job.pickup_search_flg=1';
		$this->set('pickup_jobs',$this->Job->getPickUpData($condition2,'substring(Job.pickup_img_file,0,3) desc,Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc'));
		$pagestr=$this->initPageCount($count,'件','件','中',$this->show);
		$this->set('attention_img_dir',$this->Prop->getValue('config.job.image.dir'));
		$this->set('pagestr',$pagestr);
		$this->set('jobs',$jobs);
		$this->setPaging('ajax','/search/job_search',$count,$this->show,null,$this->show);
	} */
	//@author wangyuhua 2012/4/17 end
	
	function job_search(){
		$this->initPageLeft();
		$this->pageTitle='カモメ中国転職：求人検索';
		
		//@author wangyuhua 2012/4/6 update start 注释下面语句
// 		$areas=$this->SysParams->generateList("\"SysParams\".kbn = 'area_id' and \"SysParams\".deleted is null","order by id asc");
// 		$temas=$this->SysParams->generateList("\"SysParams\".kbn = 'tema_id' and \"SysParams\".deleted is null","order by id asc");
// 		$this->set('temas',$temas);
// 		$this->set('areas',$areas);
		//@author wangyuhua 2012/4/6 end
		
		$condition="\"Job\".deleted is null and \"Job\".search_flg=0 and (\"Job\".\"public_start\"||' '||\"Job\".\"public_start_hour\"||':'||\"Job\".\"public_start_min\") <= to_char(now(),'YYYY-MM-DD HH24:MI') and (\"Job\".\"public_end\"||' '||\"Job\".\"public_end_hour\"||':'||\"Job\".\"public_end_min\")>=to_char(now(),'YYYY-MM-DD HH24:MI')" .
				" and \"Job\".job_status_id=1 and \"Job\".public_close_date is NULL"
				//lfx added 2013-09-11 start
				." AND  (\"Job\".\"cn_asia\"<>'1'  or \"Job\".\"cn_asia\" is NULL)" ;
				//lfx added 2013-09-11 end
		;
		//$order='Job.public_start'=>'desc';
		
		//@author wangyuhua 2012/4/6 update start 
		$data = $this->data;
		$f=$this->Session->read("form");
		if(!empty($this->data['Search'])){
			$condition.=' and '.$this->createCondition($this->Search,$this->data);
			$this->Session->del('form');
			$form = $data;
			$this->Session->write('form',$form);
			
			$this->Session->write('job_search_conditions',$condition);		
		}
		else{
			if($this->Session->check('job_search_conditions')){
				$condition = $this->Session->read('job_search_conditions');
			}
			
			$form=$f;
		}
		
		$this->set('form',$form);
		//@author wangyuhua 2012/4/6 update end 
		
//20081226 修正job搜索条件，attention搜索条件，pickup搜索条件

		$jobs=$this->Job->findAll($condition,null,'Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc',$this->show,$this->page);
		$count=$this->Job->findCount($condition);	
		
		$condition1=$condition.' AND to_char("Job"."attention_start",\'YYYY-MM-DD\') <= to_char(now(),\'YYYY-MM-DD\') AND to_char("Job"."attention_end",\'YYYY-MM-DD\') >= to_char(now(),\'YYYY-MM-DD\') and "Job".attention_search_flg=1';	
		$this->set('attention_jobs',$this->Job->findAll($condition1,null,'Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc'));
		$condition2=$condition.' AND to_char("Job"."pickup_start",\'YYYY-MM-DD\') <= to_char(now(),\'YYYY-MM-DD\') AND to_char("Job"."pickup_end",\'YYYY-MM-DD\') >= to_char(now(),\'YYYY-MM-DD\') and Job.pickup_search_flg=1';			
//		$this->set('pickup_jobs',$this->Job->findAll($condition2,null,'Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc'));
		//for pickup_img
		
		$pickup_jobs = $this->Job->getPickUpData($condition2,'substring(Job.pickup_img_file,0,3) desc,Job.public_start desc,Job.public_start_hour desc,Job.public_start_min desc,Job.approve_date desc');
		$this->Output->htmlspecialchars_decode($pickup_jobs);
		$this->set('pickup_jobs', $pickup_jobs);
		
		$pagestr=$this->initPageCount($count,'件','件','中',$this->show);
		$this->set('attention_img_dir',$this->Prop->getValue('config.job.image.dir'));
		$this->set('pagestr',$pagestr);
		
		$this->Output->htmlspecialchars_decode($jobs);
        $this->set('jobs',$jobs);
        $this->setPaging('ajax','/search/job_search',$count,$this->show,null,$this->show);
	}
	
	function createCondition($search, $params){
		if (!empty ($params['Search']['job_area_id'])) {
			$ids = $this->Job->getIdsBySearch($search, $params, 'job_area_inner', 'job_area_id');
			if (!empty ($ids)) {
				$params['Search']['area_id'] = $ids;
			}
		}
		if (!empty ($params['Search']['category_id'])) {
			$ids = $this->Job->getIdsBySearch($search, $params, 'job_category_inner', 'category_id');
			if (!empty ($ids)) {
				$params['Search']['category_id'] = $ids;
			}
		}
		/* if (!empty ($params['Search']['key_word'])) {
			//@author wangyuhua 2012/4/6 update start
			$arrids = array();
			$comids = split(" ",str_replace(" "," ",$params['Search']['key_word']));
			for ($i = 0; $i < count($comids); $i++) {
				$params['Search']['com_ids']=$this->Company->getComIdByName($comids[$i]);
				$ids = $this->Job->getJobIdByCom($search, $params, 'job_mst', 'com_ids');
				if (!empty ($ids) && $ids != -1) {
					$params['Search']['ids'] .= ",".$ids;
				}
// 				$arrids = array_pad($arrids,$i+1,$params['Search']['ids']);
			}
			//@author wangyuhua 2012/4/6 update end
		} */
		$ids = $this->Job->getDeleteCompanyId();

		if (!empty ($ids)) {
			$params['Search']['delete_id'] = $ids;
		}

		$sql = "Job.id in (###area_id###)" .
		" AND Job.id in (###category_id###)" .
		" AND Job.company_id not in (###delete_id###)";
		$condition=$search->calulate($sql, $params['Search']);
		if (!empty ($params['Search']['key_word'])) {
				//@author wangyuhua 2012/4/6 update start
				$condition .= ' and "Company".deleted is null ';
				$params['Search']['key_word'] = str_replace("　"," ",$params['Search']['key_word']);
				$conarr = split(" ",$params['Search']['key_word']);
				
				for ($i = 0; $i < count($conarr); $i++) {
					if (trim($conarr[$i]) != null && trim($conarr[$i]) != '') {
						//lfx modified 2013-09-12 start like ---->ilike
						$condition.=' and ("Job".title ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".small_title ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".location_title ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".work_type ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".content ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".condition ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".salary ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".start_date ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".location ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".sort ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".message ilike '.'\'%'.$conarr[$i].'%\''.
								' or "Job".attention_note ilike '.'\'%'.$conarr[$i].'%\''
								.' or "Job".company_name_other ilike '.'\'%'.$conarr[$i].'%\''
								.' or "Company".company_name ilike '.'\'%'.$conarr[$i].'%\''
								.' or "Company".company_alias ilike '.'\'%'.$conarr[$i].'%\''
								.') '
						//lfx modified 2013-09-12 end like ---->ilike
								;
					}
				}
				//@author wangyuhua 2012/4/6 end
		}

		return $condition;
	}
	
	function job_detail($job_id,$url=null){
	    $this->initPageLeft();
	    if(!is_numeric($job_id)) {
	    	$this->redirect('/errors/error404');
	    }
	    $job=$this->Job->find('"Job".deleted is null and "Job".id='.$job_id);
		//lfx add 2013-09-13 start -->update html path
	    $job['Job']['job_detail_html']=$this->Common->relative_path_set($job['Job']['job_detail_html']);
		//lfx add 2013-09-13 end -->update html path
	    
		//成立年月没有月，删除‘-’
		$last_str = substr($job['Company']['company_created'],-1);
		if($last_str == '-'){
			$job['Company']['company_created'] = substr($job['Company']['company_created'],0,-1);
		}
		$condition = "\"Job\".id=$job_id And \"Job\".job_status_id=1 AND (\"Job\".\"public_start\"||' '||\"Job\".\"public_start_hour\"||':'||\"Job\".\"public_start_min\")<=to_char(now(),'YYYY-MM-DD HH24:MI') AND (\"Job\".\"public_end\"||' '||'23:59:59')>=to_char(now(),'YYYY-MM-DD HH24:MI:SS')" .
		" AND \"Job\".public_close_date is NULL AND \"Job\".deleted is NULL";
		$condition1 = "\"Job\".id=$job_id And \"Job\".job_status_id=1 " .
		" AND (\"Job\".public_close_date is not NULL OR (\"Job\".\"public_start\"||' '||\"Job\".\"public_start_hour\"||':'||\"Job\".\"public_start_min\")>to_char(now(),'YYYY-MM-DD HH24:MI'))" .
		" AND Job.deleted is NULL";
		$public_check = $this->Job->find($condition);
		$public_check1 = $this->Job->find($condition1);
		if(!empty($public_check1) || empty($job)){
			//$this->set('overdate','この求人の募集は終了しています。');
		    $this->show4042();
		    exit;
		}
        		
		if(empty($public_check)){
			$this->set('overdate','この求人の募集は終了しています。');
		}
	    if(empty($url)){
	    	$sys=$this->SysParams->find("\"SysParams\".kbn='area_id' and \"SysParams\".id=".$job['Job']['important_area_id']);
	    	$this->set('area_img',$sys['SysParams']['description']);
	    	$this->pageTitle=$sys['SysParams']['title'].'|'.$job['Job']['title'];
	    	$this->set('area_id',$sys['SysParams']['id']);
    		$this->set('area',$sys['SysParams']['description']);
    		$this->set('Area_img',$sys['SysParams']['description']);
	    }else{
	    	$sys=$this->SysParams->find("\"SysParams\".description='$url'");
	    	if($sys['SysParams']['kbn']=='tema_id'){
	    		$data=$this->SysParams->find("\"SysParams\".kbn='area_id' and \"SysParams\".id=".$job['Job']['important_area_id']);
	    		$url=$data['SysParams']['description'];
	    		$this->set('area_id',$data['SysParams']['id']);
	    		$this->set('area',$data['SysParams']['description']);
//20081223----content_flg=tema;tema数据;
	    		$this->set('content_flg','tema');
	    		$this->set('Area_img',$sys['SysParams']['description']);
	    	}else{
	    		$this->set('area_id',$sys['SysParams']['id']);
	    		$this->set('area',$url);
//20081223----content_flg=area;area数据;
	    		$this->set('content_flg','area');
	    		$this->set('Area_img',$url);
	    	}
	    	$this->set('area_img',$url);
	    	
	    	$this->pageTitle=$sys['SysParams']['title'].'|'.$job['Job']['title'];
	    }
	    //check bookmark
	    $member_id=$this->rdAuth->id;
	    if(!empty($member_id)){
	    	$bookmark=$this->BookMark->find("\"BookMark\".job_id='$job_id' AND \"BookMark\".member_id='$member_id' AND \"BookMark\".deleted is null");
		    if(!empty($bookmark)){
		    	$bookmark_flg=true;
		    	$this->set('bookmark_flg',$bookmark_flg);
		    } 
	    }

	    if(!empty($job['Company']['logo_name'])){
	    	$job['Company']['logo_path']='/'.$this->Prop->getValue('config.image.dir').'/'.floor($job['Company']['id']/1000).'/'.$job['Company']['id'].'/'.$job['Company']['logo_name'];
	    }
	    $job['Job']['post_data']=$this->processSelects($job,'JobPost','post_id');
		$job['Job']['lang_data']=$this->processSelects($job,'JobHopeLanguage','hope_language_id');
		$job['Job']['member_data']=$this->processSelects($job,'JobHopeMember','hope_member_id');
		$job['Job']['attention_data']=$this->processSelects($job,'JobAttention','attention_id');
		$this->Output->htmlspecialchars_decode($job);
		$this->set('job',$job);
		$companyaccount=$this->CompanyAccount->find("\"CompanyAccount\".id=".$job['Job']['admin_id']." and \"CompanyAccount\".deleted is null ");
		$this->set("companyaccount",$companyaccount);
		
	}
	function processSelects($data,$key,$kbn){
		if(!isset($data[$key])){
			return '';
		}
		$arr = array();
		foreach($data[$key] as $d){
			$sysdata=$this->SysParams->find('"SysParams".kbn='.'\''.$kbn.'\''.' and "SysParams".id='.$d[$kbn]);
			if($key=='JobHopeLanguage'&&$d[$kbn]==4){
				$arr[] = $data['Job']['hope_language_note'];
			}else{
				$arr[] = $sysdata['SysParams']['name'];
			}
		}		
		return  implode(',',$arr);
		$email = "test";
		$this->Encrypt->encode($email);
	}
	
	function member_edit(){
		if($this->data['Order'] == null || empty($this->data['Order']['job_id'])) {
			$this->redirect('/errors/error404');exit;
		}
		$this->Session->write('order_info',$this->data['Order']);
		//print_r($this->data);
		$this->redirect("/member/reviseMember/".$this->data['Order']['job_id']);
	}
	
	//@author wangwei 2012/03/02 add
	function resume_edit(){
		if($this->data['Order'] == null || empty($this->data['Order']['job_id'])) {
			$this->redirect('/errors/error404');exit;
		}	
		//@author wangyuhua 2012/3/31 add start 增加了下行代码
		$this->Session->del("order_id");
		$this->Session->write('order_info',$this->data['Order']);
		//@author wangyuhua 2012/3/31 add end 增加了上行代码
		$this->Session->write('order_id',$this->data['Order']['job_id']);
		$this->redirect("/member/resume/order_input");
	}
	//@author wangyuhua 2012/2/23
	private function workTime(&$work = null) {
		for($i = 0; $i < count($work); $i++) {
			$workTime = null;
			$startYear = $work[$i]['MemberWork']['exp_work_start_year'];
			$startMonth = $work[$i]['MemberWork']['exp_work_start_month'];
			$endYear = $work[$i]['MemberWork']['exp_work_end_year'];
			$endMonth = $work[$i]['MemberWork']['exp_work_end_month'];
			$startYear = $work[$i]['MemberWork']['exp_work_start_year'];
			$workTime .= $startYear.'年'.$startMonth.'月';
			
			$workTime .= ' ～ ';
			if($work[$i]['MemberWork']['exp_work_flg'] == 0) {
				$workTime .= '在籍中';
			} else {
				$workTime .= $endYear.'年'.$endMonth.'月';
				
			}
			$work[$i]['MemberWork']['work_time'] = $workTime;
		}
	}
	private function nvl($var, $nilVar = '?') {
		if($var == null) {
			return $nilVar;
		} else {
			return $var;
		}
	}
	
	/* private function moneyFmt($money, $type) {
		switch($type) {
			case 1:
				return $money . '円';
			case 2:
				return $money . 'RMB';
			default:
				return $money;
		}
	} */
	function setIncome(&$money, $cur, $money_to, $type) {
		$cur = $this->SysParams->find("\"SysParams\".id=".$cur.
				" and \"SysParams\".kbn = 'income_cur'", 'name');
		// wang.wei update 2012/12/10
		if(!empty($money) && empty($money_to)){
			$money = number_format($money)." ".$cur['SysParams']['name'];
			if($type == 'hope_income'){
				$money .= '以上';
			}
		}
		else if(!empty($money_to) && empty($money)){
			$money = number_format($money_to)." ".$cur['SysParams']['name'].'以下';
		}else if(!empty($money_to) && !empty($money)){
			$money = number_format($money)." ～ ".number_format($money_to)." ".$cur['SysParams']['name'];
		}
		// wang.wei update 2012/3/16
		// wang.wei update 2012/3/16
		//$money = $money != '' ? number_format($money).' '.$cur['SysParams']['name']: null;
		//$money = number_format($money).' '.$cur['SysParams']['name'];
	}
	function getResumeInfo($member_id) {
		$edu = $this->MemberEducation->findAll( //学歴情報を取得する	 2012-02-23
				"\"MemberEducation\".member_id=" . $member_id . " and \"MemberEducation\".deleted is null",
				null, "MemberEducation.id ");
		
		$this->eduTime($edu);
		
		$work = $this->MemberWork->findAll( //職務経歴情報を取得する	 2012-02-23
				"\"MemberWork\".member_id=" . $member_id . " and \"MemberWork\".deleted is null",
				null, "MemberWork.id ");
		$this->workTime($work);
		$expworktype = $this->MemberExpWorktype->findAll( //会員経験職種情報を取得する	 2012-02-23
				"\"MemberExpWorktype\".member_id=" . $member_id . " and \"MemberExpWorktype\".deleted is null",
				null, "MemberExpWorktype.id ");
		$resume = $this->MemberResume->find( //職務経歴情報を取得する	 2012-02-23
				"\"MemberResume\".member_id=" . $member_id . " and \"MemberResume\".deleted is null");
		$this->setIncome($resume['MemberResume']['now_income'], $resume['MemberResume']['now_income_cur'],'','now_income');
		$resume['MemberResume']['note'] = str_ireplace("\r\n", "<br>", $resume['MemberResume']['note']);
		$resume['MemberResume']['note'] = str_ireplace("\n", "<br>", $resume['MemberResume']['note']);
// 		$resume['MemberResume']['now_income'] = $this->moneyFmt(
// 				$resume['MemberResume']['now_income'],
// 				$resume['MemberResume']['now_income_cur']);
		$this->set("expworktype", $expworktype);
		$this->set("resume", $resume);
		$this->set("edu", $edu);
		$this->set("work", $work);
	}

	/**
	 * 書式した学歴在籍情報
	 *
	 * create: 2012-03-13 ツバサ(エスワイシステム)
	 * update:　
	 * */
	private function eduTime(&$edu) {
		for ($i = 0; $i<count($edu) ;$i++) {
			if($edu[$i]['MemberEducation']['edu_start'] != null) {
				$edu[$i]['MemberEducation']['edu_start'] =
				date('Y年n月', strtotime($edu[$i]['MemberEducation']['edu_start']));
			}
			if($edu[$i]['MemberEducation']['edu_end'] != null) {
				$edu[$i]['MemberEducation']['edu_end'] =
				date('Y年n月', strtotime($edu[$i]['MemberEducation']['edu_end']));
			}
		}
	}
	
	//@author wangyuhua 2012/3/5 add
	function getMemberFmtData(&$member) {
		$member['edu'] = array();
		$key = 'SysParams';
		//留学経験
		$pointer = 26;
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['nation'] = $member[$key.($i)]['name'];
			$temp['period'] = $member[$key.($i+1)]['name'];
			$temp['purpose'] = $member[$key.($i+2)]['name'];
			if($temp['nation'] || $temp['period'] || $temp['purpose']) {
				array_push($member['edu'], $temp);
			}
		}
		//外国での勤務経験
		$pointer = 35;
		$member['work'] = array();
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['nation'] = $member[$key.($i)]['name'];
			$temp['period'] = $member[$key.($i+1)]['name'];
			$temp['purpose'] = $member[$key.($i+2)]['name'];
			if($temp['nation'] || $temp['period'] || $temp['purpose']) {
				array_push($member['work'], $temp);
			}
		}
		//@author wang.wei 2012/3/19 add start
		$pointer = 62;
		$member['language'] = array();
		for($i = $pointer; $i < $pointer + 10; $i+=2) {
			$temp = array();
			$temp['lang'] = $member[$key.($i)]['name'];
			$temp['level'] = $member[$key.($i+1)]['name'];
			if($temp['lang'] || $temp['level']) {
				array_push($member['language'], $temp);
			}
		}
		//@author wang.wei 2012/3/19 add end
		/* //語学レベル
		$pointer = 44;
		$member['language'] = array();
		for($i = $pointer; $i < $pointer + 6; $i+=2) {
			$temp = array();
			$temp['lang'] = $member[$key.($i)]['name'];
			$temp['level'] = $member[$key.($i+1)]['name'];
			if($temp['lang'] || $temp['level']) {
				array_push($member['language'], $temp);
			}
		} */
		//希望業種、職種
		$pointer = 52;
		$member['hope_work'] = array();
		for($i = $pointer; $i < $pointer + 9; $i+=3) {
			$temp = array();
			$temp['category'] = $member[$key.($i)]['name'];
			$temp['big'] = $member[$key.($i+1)]['name'];
			$temp['small'] = $member[$key.($i+2)]['name'];
			if($temp['category'] || $temp['big'] || $temp['small']) {
				array_push($member['hope_work'], $temp);
			}
		}
		//希望勤務地
		$pointer = 23;
		$member['hope_location'] = array();
		for($i = $pointer; $i < $pointer + 3; $i++) {
			$temp = $member[$key.$i]['name'];
			if($temp) {
				array_push($member['hope_location'], $temp);
			}
		}
	}
	
	function order_input($job_id,$sessClean=null){
		if(empty($job_id)) {
			$this->redirect('/errors/error404');exit;
		}
		if(empty($this->rdAuth->id)){
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login/search/job_detail/'.$job_id);
		}
		// wang.wei add 2012/5/23 start
		$this->Output->htmlspecialchars($this->data);
		// wang.wei add 2012/5/23 end
		$this->setHead();
		$member_id=$this->rdAuth->id;
		//@author wangyuhua 2012/2/22 update start
		$myMember=$this->Member->find('"Member".id='.$member_id);
// 		if($myMember['Member']['work_visa_flg']=='0'){
// 			$myMember['SysParams31']['name']='有り ';
// 		}elseif($myMember['Member']['work_visa_flg']=='1'){
// 			$myMember['SysParams31']['name']='無し';
// 		}
		if($myMember['Member']['hope_income_flg'] == 2) {
			$this->setIncome($myMember['Member']['hope_income'],$myMember['Member']['hope_income_cur'],$myMember['Member']['hope_income_to'],'hope_income');
		} else if($myMember['Member']['hope_income_flg'] == 1) {
			$myMember['Member']['hope_income'] = '希望なし';
		}
		$this->getMemberFmtData($myMember);
// 		$mem=$this->Member->getSearchInfo($member_id);
// 		$member = $mem[0][0];
		$job=$this->Job->find('"Job".id='.$job_id);

		$this->getResumeInfo($member_id);
		
		$this->set('job',$job);
// 		$this->set('member',$member);
		$this->set('myMember',$myMember);
		//@author wangyuhua 2012/2/22 update end
		if($sessClean=='true'){
			$this->Session->del('order_info');
		}
		if(empty($this->data)){
			$data = $this->Session->read('order_info');
			if(!empty($data)){
				$this->set('order',$data);//print_r($data);
			}
			$this->render('order_input');
			exit;
		}
		$form=$this->params['data']['Order'];
		$message = $this->Order->Order_valid($this->Valid,$this->data);
		$file_type1=$this->Prop->getValue('config.file_type1');
		$file_type2=$this->Prop->getValue('config.file_type2');
		$file_size=$this->Prop->getValue('config.file_size');
		

		if(!empty($form['file_name']['name'])){
			$message.=$this->Valid->ErrorMsg($form, 'file_name/size', 'file_size1', $file_size);
			$message.=$this->Valid->ErrorMsg($form, 'file_name/type', 'file_type',$file_type1);
		}
		if(!empty($form['file_name_2']['name'])){
			$message.=$this->Valid->ErrorMsg($form, 'file_name_2/size', 'file_size1', $file_size);
			$message.=$this->Valid->ErrorMsg($form, 'file_name_2/type', 'file_type',$file_type1);
		}
		if(!empty($form['file_name_3']['name'])){
			$message.=$this->Valid->ErrorMsg($form, 'file_name_3/size', 'file_size1', $file_size);
			$message.=$this->Valid->ErrorMsg($form, 'file_name_3/type', 'file_type',$file_type2);
		}
		if($message){
			// wang.wei add 2012/5/23 start
			$this->Output->htmlspecialchars_decode($this->data);
			// wang.wei add 2012/5/23 end
			$this->set('message',$message);
			$this->render('order_input');
			exit;
		}
		
		$this->FileEncrtypt->dir_confirm=$this->Prop->getValue('config.file.resume.dir_confirm');
		if(!empty($form['file_name']['name'])){
			$form['file_name1']=$form['file_name']['name'];
			$form['file_name']=$this->FileEncrtypt->saveConfirmFile($form,'file_name');
		}else{
			$form['file_name']=null;
			$form['file_name1']=null;
		}

		if(!empty($form['file_name_2']['name'])){
			$form['file_name2']=$form['file_name_2']['name'];
			$form['file_name_2']=$this->FileEncrtypt->saveConfirmFile($form,'file_name_2');
		}else{
			$form['file_name_2']=null;
			$form['file_name2']=null;
		}

		if(!empty($form['file_name_3']['name'])){
			$form['file_name3']=$form['file_name_3']['name'];
			$form['file_name_3']=$this->FileEncrtypt->saveConfirmFile($form,'file_name_3');
		}else{
			$form['file_name_3']=null;
			$form['file_name3']=null;
		}
		$this->Session->write('order_info',$form);
		$this->redirect('search/order_confirm');
	}
	function order_confirm(){
		if(empty($this->rdAuth->id)){
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login');
		}
		$this->setHead();
		$order=$this->Session->read('order_info');
		//$member=$this->Member->find('"Member".id='.$order['member_id']);
		$job=$this->Job->find('"Job".id='.$order['job_id']);
		
		//@author wangyuhua 2012/2/24
		$myMember=$this->Member->find('"Member".id='.$order['member_id']);
		if($myMember['Member']['hope_income_flg'] == 2) {
			$this->setIncome($myMember['Member']['hope_income'],$myMember['Member']['hope_income_cur'],$myMember['Member']['hope_income_to'],'hope_income');
		} else if($myMember['Member']['hope_income_flg'] == 1) {
			$myMember['Member']['hope_income'] = '希望なし';
		}
		$this->getMemberFmtData($myMember);
		
// 		$mem=$this->Member->getSearchInfo($order['member_id']);
// 		$member = $mem[0][0];
		$this->getResumeInfo($order['member_id']);
		$this->set('myMember',$myMember);
		
		$this->set('order',$order);
// 		$this->set('member',$member);
		$this->set('job',$job);
	}
	function order_save(){
		if(empty($this->rdAuth->id)){
			$this->redirect(FRONT_SERVER_HTTP.FRONT_SERVER_NAME.'/memberLogin/login');
			exit;
		}
		$this->setHead();
		if(!$this->Session->check('order_info')){
			$this->showError('session_expired');
			exit;
		}
		$order=$this->Session->read('order_info');
		$job_id=$order['job_id'];
		$member_id=$order['member_id'];
		$this->FileEncrtypt->dir_confirm=$this->Prop->getValue('config.file.resume.dir_confirm');
		$this->FileEncrtypt->dir=$this->Prop->getValue('config.file.resume.dir');
		$path=floor($job_id/1000).'/'.$job_id.'/'.floor($member_id/1000).'/'.$member_id;
		if(!empty($order['file_name'])){
			$this->FileEncrtypt->saveFile($path,$order['file_name']);
		}
		if(!empty($order['file_name_2'])){
			$this->FileEncrtypt->saveFile($path,$order['file_name_2']);
		}
		if(!empty($order['file_name_3'])){
			$this->FileEncrtypt->saveFile($path,$order['file_name_3']);
		}
		$this->Order->save($order);
		$order_id=$this->Order->getLastInsertID();
		$job=$this->Job->find('"Job".id='.$job_id);
		$member=$this->Member->find('"Member".id='.$member_id);
		
		//邮件内容
		$subject=$this->Prop->getValue('config.mail_title.company_order_finish');
		$subject=str_replace('#job_id#',$job_id, $subject);	
		
		$data['job_id']=$job['Job']['id'];
		$data['title']=$job['Job']['title'];
		$data['small_title']=$job['Job']['small_title'];
		if ($job['Job']['company_name_flg'] == '0') {
			$data['company_name']=$job['Company']['company_name'];
		} elseif($job['Job']['company_name_flg'] == '1') {
			$data['company_name']=$job['Company']['company_alias'];
		} else{
			$data['company_name']=$job['Company']['company_name_other'];
		}
		$data['location_title']=$job['Job']['location_title'];
		$data['public_start']=date('Y/m/d',strtotime($job['Job']['public_start']));
		$data['job_url']=FRONT_SERVER_NAME."/docs/$job_id";
		if($job['Company']['company_type_id']==1){
			$data['url']=ADMIN_SERVER_NAME."/job/order_detail/".$order_id;
		}else{
			$data['url']=ADMIN_SERVER_NAME."/job/order_detail/".$order_id;
		}
		
		
		/**
		 * 応募連絡メール
		 * @2009-04-01
		 * 1.応募連絡用メールアドレス	        届く
		 * 2.求人投稿担当者メールアドレス	届かない => 届く @2009-05-01
		 * 3.求人表示用メールアドレス	        届かない => 届く @2009-05-01
		 * 4.別のメールアドレス          届く
		 */
		
		//応募連絡用メールアドレス
		if(!empty($job['Job']['email1'])){
			$data['name']=$job['Job']['email1'];
			$contents=$this->getMailTemplate("company_order_finish",$data);
			$this->MailJob->saveMsg('web@kamome.cn',$data['name'],$subject,$contents,'','info@kamome.cn');
		}	
		//求人表示用メールアドレス		
		if(!empty($job['Job']['email2'])){
			$data['name']=$job['Job']['email2'];
			$contents=$this->getMailTemplate("company_order_finish",$data);
			$this->MailJob->saveMsg('web@kamome.cn',$data['name'],$subject,$contents,'','info@kamome.cn');
		}
		//その他
		if(!empty($job['Job']['email3'])){
			$data['name']=$job['Job']['email3'];
			$contents=$this->getMailTemplate("company_order_finish",$data);
			$this->MailJob->saveMsg('web@kamome.cn',$data['name'],$subject,$contents,'','info@kamome.cn');
		}
		
		//会員向けメール
		$subject=$this->Prop->getValue('config.mail_title.member_order_finish');
		$data['name']=$member['Member']['name_kanji'];
		$data['url']=FRONT_SERVER_NAME."/docs/$job_id";
		$contents=$this->getMailTemplate("member_order_finish",$data);
		$this->MailJob->saveMsg('web@kamome.cn',$member['Member']['email'],$subject,$contents,'','info@kamome.cn');
		
		$this->Session->del('order_info');
		$this->redirect('search/order_finish');
	}
	
	
	function order_finish(){
		
		$this->setHead();
	}
	
	
	/**
	 * @author wangwei
	 *
	 * create: 2012/5/4
	 * */
	function setHead() {
		header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");
		header("Last-Modified:".gmdate("D, d M Y H:i:s") . " GMT");
		header("Cache-Control: no-cache, must-revalidate");
		header("Pragma: no-cache");
	}
}
?>
